home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoAppendLargeSlots.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.9 KB  |  258 lines

  1. /*
  2.  *   $RCSfile: undoAppendLargeSlots.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:04 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "pool.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "logaction.h"
  62. #include "openlog.h"
  63. #include "undo.h"
  64. #include "undo_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "log_extfuncs.h"
  67. #include "log_intfuncs.h"
  68. #include "util_funcs.h"
  69. #include "thread_globals.h"
  70. #include "bf_globals.h"
  71. #include "trans_globals.h"
  72. #include "sm_macro.h"
  73. #ifdef INIT_LRC_IS_LSN
  74. #    include "log_globals.h"
  75. #endif
  76.  
  77.  void
  78. undoAppendLargeSlots(
  79.  
  80.     LOGRECORDHDR        *recordHeader 
  81. )
  82. {
  83.  
  84.     GROUPLINK            *groupLink;
  85.     LGNODE                *lgNode;
  86.     SLOTTEDPAGE         *slottedPage;
  87.     PAGETYPE            pageType;
  88.     PAGE2SIZE           page2size;
  89.     PAGESLOT            *slotPtr;
  90.     SMALLOBJ            *objPtr;
  91.     LRC                 *pageLRC;
  92.     PID                    *pid;
  93.     LGWRITEINFO         *lgWriteInfo;
  94.     LOGRECORDINFO       recordInfo;
  95. #ifdef INIT_LRC_IS_LSN
  96.     LRC                 tempLRC;
  97.     LRC                 *lrc = &tempLRC;
  98. #else
  99.     LRC                 *lrc;
  100. #endif /* INIT_LRC_IS_LSN; */
  101.     LSN                    lsn;
  102.     FORCEMARK            forceMark;
  103.     BOOL                actionDone;    /* Indicates whether the action
  104.                                        was ever performed on the page */
  105.     INIT_MISSING_UPDATE_INFO( Active->transRec );
  106.  
  107.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  108.  
  109.     /*
  110.      *    get a pointer to the page for the record
  111.      */
  112.     pid = &(recordHeader->actionPid);
  113.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  114.  
  115.     /*
  116.      *    get pointer to oid, header info
  117.      */
  118.     lgWriteInfo = (LGWRITEINFO*) GET_LOG_IMAGE(recordHeader, 0);
  119.  
  120.     /*
  121.      *    read in the page
  122.      */
  123.     if (lgWriteInfo->rootSlot != NIL) {
  124.         pageType = PAGE_SLOTTED;
  125.         page2size = SLOTTED_PAGE2SIZE;
  126.     } else {
  127.         pageType = PAGE_LARGENODE;
  128.         page2size = LG_PAGE2SIZE;
  129.     }
  130.     if ((groupLink = bf_ReadPage(UserBufGroup, pid, page2size, BF_SEM)) == NULL) {
  131.  
  132.         SM_ERROR(TYPE_FATAL, Active->errno);
  133.     }
  134.     groupLink->pageHash->pageType = pageType;
  135.  
  136.     /*
  137.      *    get a pointer to the large node page
  138.      */
  139.     if (lgWriteInfo->rootSlot == NIL) {
  140.         lgNode = (LGNODE *) groupLink->bufFrame;
  141.         pageLRC = &(lgNode->header.lrc);
  142.         CHECK_LARGENODE_MAGIC(lgNode);
  143.     } else {
  144.         /*
  145.          *  Root node on slotted page
  146.          */
  147.         slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  148.         pageLRC = &(slottedPage->header.lrc);
  149.         SM_ASSERT(LEVEL_3, !CHECK_SLOTTED_MAGIC(slottedPage));
  150.     }
  151.  
  152.     /*
  153.      *    See if the action was actually done
  154.      */ 
  155.     actionDone = compareLRC(&(recordHeader->actionLRC), pageLRC) <= 0;
  156.     
  157.     /*
  158.      *    it is possible that the action 
  159.      *    never made it to the page on the server, so missing update
  160.      *    information may need to be recorded
  161.      *
  162.      *    Process any missing updates, and return a pointer to
  163.      *    the lrc to increment.  This will either be the lrc on the
  164.      *    slotted page, or the lrc in the missingUpdatePageTable
  165.      */
  166.     RECORD_MISSING_UPDATE(actionDone, &lrc ,missingUpdateInfo, pid, 
  167.              pageLRC, groupLink->pageHash, recordHeader, pageType);
  168.  
  169.     /*
  170.      *    increment the lrc on the page
  171.      */
  172.     GENERATE_LRC(lrc);
  173.  
  174.     /*
  175.      *    Log the undo of the append
  176.      */
  177.     if (recordHeader->action == LOG_ACTION_APPEND_LARGE_SLOTS) {
  178.         recordInfo.action       = LOG_ACTION_REMOVE_LARGE_SLOTS;
  179.     } else {
  180.         SM_ASSERT(LEVEL_3, recordHeader->action == LOG_ACTION_INSERT_LARGE_SLOTS);
  181.         recordInfo.action       = LOG_ACTION_DELETE_LARGE_SLOTS;
  182.     }
  183.     recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  184.     recordInfo.imageCount   = 1;
  185.     recordInfo.actionPid    = pid;
  186.     recordInfo.actionLRC    = lrc;
  187.     recordInfo.imageSize[0] = sizeof(LGWRITEINFO);
  188.     recordInfo.imageData[0] = (VOID *) lgWriteInfo;
  189.     recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  190.     recordInfo.flags        = NOFLAGS;
  191.  
  192.     /*
  193.      *    write the record to the log
  194.      */
  195.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  196.                               &lsn, NOFLAGS)) < 0)  {
  197.         SM_ERROR(TYPE_FATAL, Active->errno);
  198.     }
  199.  
  200.     /*
  201.      *    mark the page dependency
  202.      */
  203. #ifndef INIT_LRC_IS_LSN
  204.     DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  205. #endif
  206.  
  207.     /*
  208.      *    perform the undo, if the action was performed
  209.      */
  210.     if (actionDone) {
  211.  
  212. #ifdef INIT_LRC_IS_LSN
  213.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  214. #endif
  215.  
  216.         /*
  217.          *    get a pointer to the large node page
  218.          */
  219.         if (lgWriteInfo->rootSlot != NIL) {
  220.             /*
  221.              *  Root node on slotted page
  222.              */
  223.             SM_ASSERT(LEVEL_3, lgWriteInfo->rootSlot < slottedPage->header.slotCount);
  224.             slotPtr = GETSLOTPTR(slottedPage, lgWriteInfo->rootSlot);
  225.             objPtr = GETOBJECTPTR(slottedPage, slotPtr);
  226.             lgNode = (LGNODE*) objPtr->data;
  227.             CHECK_SLOTROOT_MAGIC(lgNode);
  228.         }
  229.  
  230.         if (recordHeader->action == LOG_ACTION_INSERT_LARGE_SLOTS)  {
  231.             /*
  232.              *     Shift slots down to delete
  233.              */
  234.             bcopy( ((char*)lgNode->slot)+lgWriteInfo->start+lgWriteInfo->size,
  235.                   ((char*)lgNode->slot)+lgWriteInfo->start,
  236.                   (int) (lgNode->header.numSlots*sizeof(LGSLOT)) - lgWriteInfo->start - lgWriteInfo->size);
  237.  
  238.         }
  239.  
  240.         /*
  241.          *    Restore the old data
  242.          */
  243.         lgNode->header.numSlots -= lgWriteInfo->size / sizeof(LGSLOT);
  244.     }
  245.  
  246.     /*
  247.      *    signal the semaphore and unfix the page, dirty the page if
  248.      *    the action was done
  249.      */
  250.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  251.     bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  252.  
  253.     /*
  254.      *    return success
  255.      */
  256.     return;
  257. }
  258.